<template>
  <transition name="scale">
    <div class="ui-card" v-show="show" @click="test">
      <div class="ui-card-content">
        <div class="ui-card-top">
          <div class="ui-card-title" :style="{ color: titleColor }">
            {{ title }}
          </div>
          <div class="ui-card-introduction gray">{{ introduction }}</div>
        </div>
        <div class="ui-card-bottom">
          <div class="ui-card-number">
            {{ getFormatNumber }}<span>{{ getUnit }}</span>
          </div>
          <div class="ui-card-prompt gray">{{ prompt }}</div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import api from '../../assets/js/url'
export default {
  name: "UiCard",
  props: {
    title: {
      type: String,
      default: ""
    },
    introduction: {
      type: String,
      default: ""
    },
    number: {
      type: String,
      default: 0
    },
    prompt: {
      type: String,
      default: ""
    },
    type: {
      type: String,
      default: "amount" // amount 金额  percentage 百分比  decimal 小数
    },
    titleColor: {
      type: String,
      default: "#000"
    },
    productID: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      show: false
    };
  },
  methods: {
    test () {
      console.log('this is productID', this.productID)
      sa.track('$CollectFinancialClick', {
        '$url_path': this.productID
      })
      let params = {
        id: this.productID
      }
      this.$remote(api.PRODUCT_DETAIL, params)
        .then(res => {
          console.log('this is product detail', res)
          this.$router.push({name: 'productDetail', query: res})
        })
    }
  },
  mounted() {
    this.show = true;
  },
  computed: {
    getFormatNumber() {
      let str = "";
      switch (this.type) {
        case "amount":
          str = this.number
          break;
        case "percentage":
          str = this.number
          break;
        case "decimal":
          str = this.number
          break;
        default:
          break;
      }
      return str;
    },
    getUnit() {
      let str = "";
      switch (this.type) {
        case "amount":
          str = "%";
          break;
        case "percentage":
          str = "%";
          break;
        default:
          break;
      }
      return str;
    }
  }
};
</script>

<style scoped>
.ui-card {
  /* width: 100px; */
  min-width: 100px;
  height: 90px;
  background: #efefef;
  display: inline-block;
  font-size: 14px;
  padding: 10px 0 8px 0;
  transform: scale(1);
  opacity: 1;
}
.ui-card-title {
  width: 100%;
  
}
.ui-card-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-direction: column;
}
.ui-card-top {
  text-align: left;
}
.ui-card-top,
.ui-card-bottom {
  padding-left: 10px;
}

.ui-card-introduction {
  line-height: 24px;
}

.ui-card-number {
  color: red;
  font-size: 20px;
  font-weight: 600;
}

.ui-card-number > span {
  font-size: 8px;
}

.ui-card-prompt {
  transform: scale(0.8);
  transform-origin: left;
}

.gray {
  font-size: 12px;
  color: #888;
}

.scale-leave-to,
.scale-enter {
  transform: scale(0);
  opacity: 0;
}

.scale-enter-active,
.scale-leave-active {
  transition: transform 0.5s ease, opacity 0.5s ease;
}
</style>
